﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef AudioManager_h__
#define AudioManager_h__

#include <string>
#include <memory>

#include "../utility/Singleton.h"

namespace SkyEngine2d
{
	class GameWorld;

	//! 音频管理 
	class AudioManager
		:public Singleton<AudioManager,false>
	{
	public:
		~AudioManager();
	
		//! 加载音乐
		/*!
		\param const std::wstring & file_path 音频文件的路径
		\return int 音频的ID
		一般在进入场景时进行 音频文件的加载 ，避免在游戏过程中加载音频
		如果加载失败，返回的Id为 -1
		*/
		int loadAudio(const std::wstring & file_path);
	
		//! 卸载音频
		/*!
		\param int id 音频ID
		\return void  
		音频卸载后，Id 会变的失效，如果要播放，需要重新加载
		*/
		void unloadAudio(int id);
	
		//! 卸载所有加载过的音频
		/*!
		\return void  
		*/
		void unloadAllAudio();
	
		//! 播放音频
		/*!
		\param int id 音频的Id
		\param bool is_loop 是否循环播放
		\return bool  播放是否成功 ，如果ID的无效的，则会返回失败
		*/
		bool playAudio(int id,bool is_loop = false);
	
		//! 停止播放音频
		/*!
		\param int id 音频ID
		\return void  
		*/
		void stopAudio(int id);
	
		//! 暂停音频
		/*!
		\param int id 音频ID
		\return void  
		*/
		void pauseAudio(int id);
	
		//! 恢复音频的播放，会从暂停的地方开始播放
		/*!
		\param int id 音频的ID
		\return void  
		*/
		void resumeAudio(int id);
	
		//! 是否正在播放
		/*!
		\param int id 音频Id
		\return bool  
		*/
		bool isPlaying(int id);
	
		//! 暂停所有正在播放的音频
		/*!
		\return void  
		*/
		void pauseAllAudio();
	
		//! 恢复所有正在播放的音频
		/*!
		\return void 
		*/
		void resumeAllAudio();
	
		//! Id 是否有效
		/*!
		\param int id 
		\return bool  
		*/
		bool isValidId(int id);
	private:
		AudioManager();
		friend class GameWorld;
		struct Imp;
		std::unique_ptr<Imp> m_imp;
	};
	
}

#endif // AudioManager_h__
